/*
 * Copyright © 2011 SenseForce.com.
 * The Software shall be used for Good, not Evil.
 */

package com.senseforce.classes;

import java.io.*;

/**
 *
 * @author jcccn
 * @site http://www.senseforce.com/
 */
public class PhoneBookContact {
	private String cname = "";
	private String phone = "";
	
	public PhoneBookContact() {
		
	}
	
	//对象转化为字符数组
	public byte[] object2ByteArray() throws Exception {
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		dos.writeUTF(cname);
		dos.writeUTF(phone);
		dos.close();
		baos.close();
		return baos.toByteArray();
	}
	
	//字符数组转化为对象
	public static PhoneBookContact byteArray2Object(byte[] bytes) throws Exception {
		ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
		DataInputStream dis = new DataInputStream(bais);
		PhoneBookContact contact = new PhoneBookContact();
		contact.setCname(dis.readUTF());
		contact.setPhone(dis.readUTF());
		dis.close();
		bais.close();
		return contact;
	}
	
	public String getCname() {
		return cname;
	}
	
	public void setCname(String cname) {
		this.cname = cname;
	}
	
	public String getPhone() {
		return phone;
	}
	
	public void setPhone(String phone) {
		this.phone = phone;
	}
}
